package com.yunhe.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yunhe.dao.UserMapper;
import com.yunhe.model.Page;
import com.yunhe.model.UserModel;
import com.yunhe.service.IUserService;

@Service("userService")
public class UserServiceImpl implements IUserService {
	@Autowired
	private UserMapper userMapper;
    /**
     * 查询用户
     */
	@Override
	public UserModel getUser(UserModel user) {
		return userMapper.getUser(user);
	}
     /**
      * 添加用户
      */
	@Override
	public void addUser(UserModel user) {
    userMapper.addUser(user);
	}
    /**
     * 删除用户
     */
	@Override
	public void delUser(UserModel user) {
      userMapper.delUser(user);
	}
    /**
     * 修改用户
     */
	@Override
	public void editUser(UserModel user) {
        userMapper.editUser(user);
	}

	@Override
	public Page queryLikeUser(Map<String, Object> cond) {
		Page page = new Page();
		page.setTotalNum(userMapper.getLikeUserCount(cond));
		int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
		int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		page.setResult(userMapper.getLikeUser(cond));
		return page;
	}

}
